<?php

namespace App\Helpers;

use Illuminate\Support\Facades\Log;

class DispatchLog
{
    /**
     * @var null|DispatchLog
     */
    private static ?DispatchLog $obj = null;
    /**
     * @var null|string
     */
    public ?string $phone = null;

    /**
     * @var array
     */
    public array $logs = [];

    public function log($msg)
    {
        $this->logs[] = $msg;
    }

    public static function make($phone)
    {
        if (self::$obj) return;
        self::$obj = new static();
        self::$obj->phone = $phone;
        self::$obj->log("$phone 开始分配");
    }

    public static function pushLog($msg)
    {
        if (!self::$obj) return;
        self::$obj->log($msg);
    }

    public static function outputLog()
    {
        if (!self::$obj) return;
        $phone = self::$obj->phone;
        Log::debug("分配日志:$phone", self::$obj->logs);
        self::$obj = null;
    }
}
